package api

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"path/filepath"
	"time"
	"video/pkg"
)

func Upload(c *gin.Context) {
	file, _ := c.FormFile("video")

	if file.Size > 10*1024*1024 {
		c.JSON(http.StatusInternalServerError, gin.H{"message": "视频过大"})
		return
	}
	ext := filepath.Ext(file.Filename)
	if ext != ".mp4" {
		c.JSON(http.StatusInternalServerError, gin.H{"message": "格式错误"})
		return
	}
	open, _ := file.Open()
	filename := time.Now().Format("2006-01-02 15:04:05") + ext
	ny, err := pkg.QiNY(open, filename)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"message": "视频上传失败"})
		return
	}
	c.JSON(http.StatusOK, gin.H{"message": "成功", "url": ny})
}
